package one.stand.service.impl;

import one.stand.enums.EnumUtil;
import one.stand.enums.LoginEnum;
import one.stand.model.NoticeModel;
import one.stand.model.ResultModel;
import one.stand.request.NoticeRequest;
import one.stand.response.NoticeResponse;
import one.stand.service.NoticeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: QIK
 * @CreateDate: 2019/5/28 15:13
 */
@Service
public class NoticeServiceImpl extends PublicBaseService implements NoticeService {
    @Override
    public ResultModel<List<NoticeResponse>> selectEffectiveList(NoticeRequest request) {
        LoginEnum loginEnum= EnumUtil.getByIntegerTypeCode(LoginEnum.class,"getCode",request.getLoginProgramName());
        List<NoticeResponse> responseList=new ArrayList<>();
        List<NoticeModel> modelList=noticeMapper.selectEffectiveList(new NoticeModel(){{
            setNoticeType(loginEnum.getAccountType());
        }});
        modelList.forEach(m->{{
            NoticeResponse response=new NoticeResponse();
            BeanUtils.copyProperties(m,response);
            responseList.add(response);
        }});
        return ResultModel.success(responseList);
    }
}
